package com.lmqb.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lmqb.bean.LmUser;
import com.lmqb.bean.SysBlack;
import com.lmqb.bean.SysWhiteList;
import com.lmqb.dao.LmUserMapper;
import com.lmqb.dao.SysBlackMapper;
import com.lmqb.dao.SysWhiteListMapper;
import com.lmqb.page.PageTool;
import com.lmqb.page.SysWhiteListrPager;
import com.lmqb.service.SysWhiteListService;
import com.lmqb.util.StrUtil;

@Service("sysWhiteListService")
public class SysWhiteListServiceImpl implements SysWhiteListService{

	@Autowired
	private SysWhiteListMapper sysWhiteListMapperDao;
	
	@Autowired
	private SysBlackMapper  SysBlackMapperDao;
	
	@Autowired
	private LmUserMapper  LmUserMapperDao;
	
	//通过白名单id找对象
	public SysWhiteList selectByPrimaryKey(Integer whiteId) {
		SysWhiteList sysWhiteList = sysWhiteListMapperDao.selectByPrimaryKey(whiteId);
		return sysWhiteList;
	}

    //添加白名单
	public int insert(SysWhiteList sysWhiteList) {
		int insert = sysWhiteListMapperDao.insert(sysWhiteList);
		return insert;
	}

	//删除
	public int deleteByPrimaryKey(SysWhiteList sysWhiteList){
		int i = sysWhiteListMapperDao.deleteByPrimaryKey(sysWhiteList);
		return i;
	}

	//白名单列表
	public SysWhiteListrPager selectAll(SysWhiteListrPager pagerModel) {
		
		List<SysWhiteList> selectAll = sysWhiteListMapperDao.selectAll(pagerModel);
		System.out.println(selectAll.size()+"-->"+selectAll);
		for(int i=0;i<selectAll.size();i++){
			selectAll.get(i).setCreateTimeD(StrUtil.intToTime(selectAll.get(i).getCreateTime()));
			selectAll.get(i).setLastUpdateTimeD(StrUtil.intToTime(selectAll.get(i).getLastUpdateTime()));
		}
		pagerModel.setList(selectAll);
		int count = sysWhiteListMapperDao.selectCount(pagerModel);
		pagerModel.setTotalRow(count);
		int totalPage = PageTool.getTotalPage(count, pagerModel.getPageSize());
		pagerModel.setTotalPage(totalPage);
		return pagerModel;
	}

	@Override
	public Integer selectCount(SysWhiteListrPager pagerModel) {
		
		return null;
	}

	//修改整个对象
	public int updateBySysWhiteList(SysWhiteList sysWhiteList) {
		int i = sysWhiteListMapperDao.updateBySysWhiteList(sysWhiteList);
		return i;
	}

	//查看黑名单是否存在这个用户
	public Integer selectByMobile(String userMobile) {
		
		Integer selectByMobile = SysBlackMapperDao.selectByMobile(userMobile);
		return selectByMobile;
	}

	//根据手机号删除黑名单
	public int deleteByMobile(String userMobile) {
		int i = SysBlackMapperDao.deleteByMobile(userMobile);
		return i;
	}

	//通过手机号找用户
	public LmUser selectLmUserByMobile(String userMobile) {
		LmUser selectByMobile = LmUserMapperDao.selectByMobile(userMobile);
		return selectByMobile;
	}



	

}
